//
//  EGMBleHandler.h
//  HBSDKPro
//
//  Created by LRB_C on 2020/8/14.
//  Copyright © 2020 林瑞彬. All rights reserved.
//

//EGMBleManager 蓝牙核心处理类  扫描 连接 读取服务 属性 是否连接 是否开启蓝牙等
//EGMBleHandler sdk协议核心了类 扫描连接指定服务协议的蓝牙设备 读取计步睡眠心率 设置功能开关吃药提醒处理类

#import <Foundation/Foundation.h>
#import "EGMLibrary.h"
#import "EGMBleOperClient.h"


typedef void(^peripheralsBlock)(NSArray<CBPeripheral*>*peripherals);
typedef void(^connectBlock)(BOOL isConnect);

@protocol EGMBleHandlerDelagate;

@interface EGMBleHandler : NSObject

@property(strong,nonatomic) EGMBleManager *bleManager;//蓝牙核心工具
@property(strong,nonatomic) EGMBleOperClient *operClient;//蓝牙数据读写操作工具类
@property (nonatomic,strong) BLeDeviceInfoModel *currentDeviceInfo; //当前连接的设备信息
@property (nonatomic,weak) id <EGMBleHandlerDelagate> delegate;//代理

+(instancetype)sharedBleHandler;

/**
扫描符合服务规范的蓝牙设备
*/
-(void)scanBLeDeviceWtihBlock:(peripheralsBlock)resultBlock;

/**
 扫描符合的匹配过的蓝牙设备
 UUIDArray:蓝牙设备的NSUUID字符串 [CBPeripheral.identifier UUIDString],当蓝牙链接后自行缓存
 */
-(void)scanRetriveBLeDeviceWtihNSUUIDArray:(NSArray*)NSUUIDArray Block:(peripheralsBlock)resultBlock;

/**
 停止扫描
 */
-(void)stopScan;


/**
 连接指定设备
 */
-(void)connectPeripheral:(CBPeripheral*)peripheral conectBlok:(connectBlock)block;

/**
 连接缓存的匹配过的设备
 uuid NSUUID 通过[CBPeripheral.identifier UUIDString]获取
 */
-(void)tryToScanAndConnectPeripheralWIthNSUUIDStr:(NSString*)uuid conectBlok:(connectBlock)block;;

/**
 断开当前蓝牙连接
 */
-(void)disConnectCurretPeripheral;

/**
 断开指定蓝牙连接
 */
-(void)disConnectPeripheral:(CBPeripheral*)peripheral conectBlok:(connectBlock)block;

/**
 当前是否连接有蓝牙设备
 */
-(BOOL)deviceIsConnected;
@end



//相关代理
@protocol EGMBleHandlerDelagate <NSObject>

@optional

-(void)handleMsgConnected;//断开连接
-(void)handleMsgDisconnected;//连接
-(void)handleMsgBtPowerOff; //蓝牙关闭
-(void)handleMsgBtPowerOn;//蓝牙打开
-(void)handleMsgBtResetting;//蓝牙重置
@end
